package com.hua.nailcampus.acl.controller;


import com.alibaba.fastjson.JSONObject;
import com.hua.nailcampus.acl.model.Messages;
import com.hua.nailcampus.socket.WebSocketServer;
import lombok.Data;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Program: springboot_websocket
 * @ClassName WebSocketController
 * @Author: chenjianhua
 * @Description: websocket web层
 * @Create: 2022-08-19 19:01
 * @Version 1.0
 **/
@Slf4j
@RestController
@RequestMapping("/ws")
public class WebSocketController {
    @Autowired
    private WebSocketServer webSocketServer;

    /**
     * 消息发送
     */
    @GetMapping("/send")
    @ResponseBody
    public void send(String content, String toUserID,String fromUserID){
        webSocketServer.sendMessage(content, toUserID,fromUserID);
    }

    /**
     * 群发消息测试(给当前连接用户发送)
     */
    @GetMapping("/sendMassMessage")
    public void sendMassMessage(){
        Messages messages = new Messages();
        webSocketServer.sendMassMessage(JSONObject.toJSONString(messages));
    }


}